package com.peter.baselibrary.base

import com.peter.electronicmall.base.IBaseView
import com.peter.electronicmall.base.IPresenter

/**
 * Created by peter on 2018/5/23.
 */
open class BasePresenter<T : IBaseView> : IPresenter<T> {

    var view: T? = null

    override fun attachView(view: T) {
        this.view = view

    }

    override fun detachView() {
        this.view = null

    }

    private val isViewAttached: Boolean
        get() = view != null

    fun  checkViewAttached(){
        if (!isViewAttached) throw MvpViewNotAttachedException()
    }

    private class MvpViewNotAttachedException internal constructor() : RuntimeException("Please call IPresenter.attachView(IBaseView) before" + " requesting data to the IPresenter")
}